#include "gui_label.h"
#include "type_gui.h"

label* gui_label_new_label(main_obj *mobj, gchar *text) {
    label *l = g_malloc0(sizeof (label));
    l->text = g_string_new(text);
    l->ge.posx = 0;
    l->ge.posy = 0;
    l->ge.redraw = TRUE;
    l->ge.focused = FALSE;
    l->ge.type = GUI_LABEL;
    l->paint = gui_label_normal_paint;
    l->update = gui_label_normal_update;
    SDL_Surface *t = gui_util_drawtext(mobj->gm->current_font, 255, 255, 255, 255, 0, 0, 0, 0, l->text->str);
    l->ge.graphic = gui_util_get_new_empty_surface(t->w, t->h);
    SDL_BlitSurface(t, 0, l->ge.graphic, 0);
    return l;
}

gboolean gui_label_set_text(label *l, gchar *text) {
    l->text = g_string_assign(l->text, text);
    l->ge.redraw = TRUE;
    return TRUE;
}

gboolean gui_label_normal_paint(main_obj *mobj, label *l) {
    SDL_Surface *t = gui_util_drawtext(mobj->gm->current_font, 255, 255, 255, 255, 0, 0, 0, 0, l->text->str);
    l->ge.graphic = gui_util_get_new_empty_surface(t->w, t->h);
    SDL_BlitSurface(t, 0, l->ge.graphic, 0);
    return TRUE;
}

gboolean gui_label_normal_update(main_obj *mobj, label *l)
{
    return TRUE;
}
